import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../components/index.vue';
import Register from '../components/register.vue';
import NotFound from '../components/404.vue';
import Login from "../components/login.vue";
import Home from "../components/home.vue";
import InfoShow from "../components/infoshow.vue";
import FundList from "../components/fundlist.vue";




Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/index',
    component: Index
  },
  {
    path: '/index',
    name: '/index',
    component: Index,
    children:[
      {path:'/home',name:'home',component:Home},
      {path:'/infoshow',name:'infoshow',component:InfoShow},
      {path:'/fundlist',name:'fundlist',component:FundList}
    ]
  },  
  {
    path: '/register',
    name: '/register',
    component: Register
  },  
  {
    path: '/login',
    name: '/login',
    component: Login
  },
  {
    path: '*',
    name: '/404',
    component: NotFound
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//路由守卫
router.beforeEach((to,from,next)=>{
  const isLogin=localStorage.eleToken ? true :false;
  if(to.path=='/login'||to.path=='/register'){
    next();
  }else{
    isLogin?next():next('/login')
  }

})
export default router
